<?php
/**
 * Created by PhpStorm.
 * User: ront
 * Date: 2018/8/7
 * Time: 16:47
 */

namespace App\Services;

use App\Models\Admin\Permission;
use App\Models\Admin\Role;

class Admin
{
    protected $permissions;

    /**
     * 查询用户权限
     * @param int $role_id
     * @return null|mixed
     */
    public static function getPermission($role_id = 0)
    {
        $role = Role::find($role_id);
        if (!$role) {
            return null;
        }
        $res = ['role' => $role->name];
        if ($role->permissions === '*') {
            $res['permissions'] = '*';
            return $res;
        }
        $permissions = Role::where('id',  $role_id)->value('permissions');
        $res['permissions'] = $permissions;
        return $res;
    }
}